require 'i18n_form_helper/form_select_options'

module ActionView
  module Helpers
    class FormBuilder

      # English => English      
      def language_name_select(method, options = {}, html_options = {}, &block)
        @template.select(@object_name, method, FormSelectOptions::LanguageOptions.english_name_to_english_name, objectify_options(options), @default_options.merge(html_options), &block)
      end

      # Norge => Norge
      def language_native_select(method, options = {}, html_options = {}, &block)
        @template.select(@object_name, method, FormSelectOptions::LanguageOptions.native_name_to_native_name, objectify_options(options), @default_options.merge(html_options), &block)
      end

      # en => English
      # no => Norsk
      def language_code_select(method, options = {}, html_options = {}, &block)
        @template.select(@object_name, method, FormSelectOptions::LanguageOptions.code_to_native_name, objectify_options(options), @default_options.merge(html_options), &block)
      end

      # United States => United States
      def country_name_select(method, options = {}, html_options = {}, &block)
        @template.select(@object_name, method, FormSelectOptions::CountryOptions.english_country_name_to_english_country_name, objectify_options(options), @default_options.merge(html_options), &block)
      end

      # US => United States
      def country_code_select(method, options = {}, html_options = {}, &block)
        @template.select(@object_name, method, FormSelectOptions::CountryOptions.code_to_english_country_name, objectify_options(options), @default_options.merge(html_options), &block)
      end

    end

    module FormTagHelper
      # English => English
      def language_name_select_tag(name, options = {})
        select_tag(name, options_for_select(FormSelectOptions::LanguageOptions.english_name_to_english_name, options.delete(:selected)), options)
      end

      # Norge => Norge
      def language_native_select_tag(name, options = {})
        select_tag(name, options_for_select(FormSelectOptions::LanguageOptions.native_name_to_native_name, options.delete(:selected)), options)
      end

      # en => English
      # no => Norsk
      def language_code_select_tag(name, options = {})
        select_tag(name, options_for_select(FormSelectOptions::LanguageOptions.code_to_native_name, options.delete(:selected)), options)
      end

      # United States => United States
      def country_name_select_tag(name, options = {})
        select_tag(name, options_for_select(FormSelectOptions::CountryOptions.english_country_name_to_english_country_name, options.delete(:selected)), options)
      end

      # US => United States
      def country_code_select_tag(name, options = {})
        select_tag(name, options_for_select(FormSelectOptions::CountryOptions.code_to_english_country_name, options.delete(:selected)), options)
      end

    end
  end
end
